--#include "data\functions\Activity\OpenServer\OpenServerCommon.lua" once

--充值金额
function OpenServerFirstRechargeWithDrawYuanbao(sysarg, nYuanBao)
	local var = Actor.getStaticVar(sysarg)
	if not var.openServerFirstRechargeCount then
		var.openServerFirstRechargeCount = {}
	end

	local len = #OpenServerFirstRechargeCfg.rechargeList
	for idx = 1, len do
		local cfg = OpenServerFirstRechargeCfg.rechargeList[idx]
		if cfg then
			if cfg.yuanbao == nYuanBao then
				local count = var.openServerFirstRechargeCount[cfg.id] or 0
				--if count >= cfg.count then
				--	return
				--end
				--local days = System.getDaysSinceOpenServer()
				--if days > cfg.days then
				--	return
				--end
			  	--不限制次数，开服天数
			    var.openServerFirstRechargeCount[cfg.id] = count + 1
				--奖励获取
				local award = { type = qatYuanbao, count = 0, }	
				if count == 0 then
					award.count = cfg.addyuanbao
				else
					award.count = cfg.otheryuanbao
				end
				
				local awards = {award}
				local logId,logStr = LogIds.OpenServerFirstRechargeLogId, Lang.LogTips.OpenServerFirstRecharge
				GiveCommonAward(sysarg, awards, logId,logStr)

				GetOpenServerFirstRecharge(sysarg)

				local title = Lang.ScriptTips.OpenServerFirstRecharge001
				local content = string.format(Lang.ScriptTips.OpenServerFirstRecharge002, nYuanBao, award.count)
				Awards.GiveToMailById(Actor.getActorId(sysarg), {}, title, content, logId,logStr)
				break
			end
		end
	end
end

--开服前几次充值
function GetOpenServerFirstRecharge(sysarg)
	local netPack = DataPack.allocPacket(sysarg, LogicCmd.miscSys.sysId, LogicCmd.miscSys.sub.sOpenServerFirstChargeData) 
	if not netPack then return end
	local var = Actor.getStaticVar(sysarg)
	if not var.openServerFirstRechargeCount then
		var.openServerFirstRechargeCount = {}
	end
	local len = #OpenServerFirstRechargeCfg.rechargeList
	DataPack.writeByte(netPack, len)

	for idx = 1, len do
		local cfg = OpenServerFirstRechargeCfg.rechargeList[idx]
		if cfg then
			local state = var.openServerFirstRechargeCount[cfg.id] or 0
			DataPack.writeByte(netPack, cfg.id)
			DataPack.writeByte(netPack, state)
		else
			DataPack.writeByte(netPack, 0)
			DataPack.writeByte(netPack, 0)
		end
	end

	DataPack.flush(netPack)
end


